package routers

import (
	v1 "ginblog/api/v1"
	"ginblog/middleware"
	"ginblog/utils"
	"github.com/gin-gonic/gin"
)

func InitRouter() {
	gin.SetMode(utils.AppMode)
	r := gin.Default()
	r.Use(middleware.Logger())
	r.Use(gin.Recovery())

	auth := r.Group("api/v1")
	auth.Use(middleware.JwtToken())
	{
		/**
		 ** 用户模块的路由接口
		 */
		auth.PUT("user/:id", v1.EditUser)
		auth.DELETE("user/:id", v1.DeleteUser)

		/**
		 ** 分类模块的路由接口
		 */
		auth.POST("category/add", v1.CreateCategory)
		auth.PUT("category/:id", v1.EditCategory)
		auth.DELETE("category/:id", v1.DeleteCategory)

		/**
		 ** 文章模块的路由接口
		 */
		auth.POST("article/add", v1.CreateArticle)
		auth.PUT("article/:id", v1.EditArticle)
		auth.DELETE("article/:id", v1.DeleteArticle)

		// 上传文件
		auth.POST("upload", v1.UpLoad)

	}

	router := r.Group("api/v1")
	{
		router.POST("user/add", v1.CreateUser)
		router.GET("users", v1.GetUsers)
		router.GET("categories", v1.GetCategories)

		// 查询所有文章
		router.GET("articles", v1.GetAllArticles)

		// 查询单个分类下的所有文章
		router.GET("articles/categoryList/:id", v1.GetCategoryArticles)

		// 查询单个文章信息
		router.GET("article/info/:id", v1.GetArticleInfo)
		router.POST("login", v1.Login)
	}

	r.Run(utils.HttpPort)

}
